package org.cllib.math;

import java.util.Iterator;

public class Range implements Iterable<Integer> {
	int min, max;

	public Range(int max) {
		min = 0;
		this.max = max;
	}

	public Range(int min, int max) {
		super();
		this.min = Math.min(min, max);
		this.max = Math.max(min, max);
	}

	public int getMin() {
		return min;
	}

	public void setMin(int min) {
		this.min = min;
	}

	public int getMax() {
		return max;
	}

	public void setMax(int max) {
		this.max = max;
	}

	public Iterator<Integer> iterator() {
		Iterator<Integer> i = new Iterator<Integer>() {
			int current = min;

			public boolean hasNext() {
				return current <= max;
			}

			public Integer next() {
				return current++;
			}

			public void remove() {
				current++;
			}

		};
		return i;
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return "[" + min + "," + max + "]";
	}

}
